#include <riscv/csr.h>
#include <riscv/thread-size.h>
#include <riscv/asm.h>

    .global  _start
    .section ".start", "ax"

_start:
    j _start_kernel



_start_kernel:
    /* Mask all interrupts */
    csrw CSR_IE, zero
    csrw CSR_IP, zero

	/* Load the global pointer */
    load_global_pointer

    /* Restore C environment */
    la tp, init_task
    la sp, init_stack + THREAD_SIZE

    /* a0: hartid,a1: dtb_pa, a2: start_pa */
    la a2, _start
    call early_setup
#ifdef CONFIG_MMU
    /* early_setup return SATP */
    sfence.vma
    csrw CSR_SATP, a0
    sfence.vma
#endif

    call setup_trap_vector

    tail start_kernel
